Optimize control-flow convergence on simd engine using divergence depth

ABSTRACT

There are provided a system, a method and a computer program product for selecting an active data stream (a lane) while running SPMD (Single Program Multiple Data) code on SIMD (Single Instruction Multiple Data) machine. The machine runs an instruction stream over input data streams. The machine increments lane depth counters of all active lanes upon the thread-PC reaching a branch operation. The machine updates the lane-PC of each active lane according to targets of the branch operation. The machine selects an active lane and activates only lanes whose lane-PCs match the thread-PC. The machine decrements the lane depth counters of the selected active lanes and updates the lane-PC of each active lane upon the instruction stream reaching a first instruction. The machine assigns the lane-PC of a lane with a largest lane depth counter value to the thread-PC and activates all lanes whose lane-PCs match the thread-PC.

FIELD OF INVENTION

This disclosure relates generally to SIMD (Single Instruction MultipleData) or SPMD (Single Program Multiple Data) computing machines, andparticularly to running an SPMD code on SIMD machine.

BACKGROUND OF THE INVENTION

Single Program Multiple Data (SPMD) refers to a parallel computingmechanism in which programs or tasks are split across a plurality ofprocessors which are configured to operate on each different data. SPMDapplies a scalar and sequential program (“SPMD kernel” or “SPMD code”)simultaneously to multiple data streams. Examples of SPMD include, butare not limited to: OpenMP® (Open Multi-Processing), Fork-join, Pthread(POSIX (Portable Operating System Interface) Thread), Map-reduce, CUDA®(Compute Unified Device Architecture), OpenCL® (Open ComputingLanguage), etc. An SPMD programming model includes running a pluralityof software threads or software processes, each of which maintains itsown program counter (PC) and states stored in its own register. Anycontrol-flow operation in SPMD code (i.e., running the SPMD kernel asmultiple instruction streams), when applied to multiple data streams,may produce multiple local PCs, which is called control-flow divergence.Control-flow divergence is a runtime behavior in a SPMD code, where PCsof multiple instruction streams of the SPMD code differ amongthemselves.

Single Instruction Multiple Data (SIMD) refers to a parallel computingmechanism in which a plurality of processors are configured to performsame operations on different data. Examples of SIMD machine includes,but is not limited to: AltiVec machine (i.e., a machine running AltiVec®(i.e., an instruction set designed for a SIMD machine)), VMX server(i.e., a server running Vintela Management Extensions (VMX)), SSEmachine (i.e., machine running Streaming SIMD Extensions (SSE), which isan instruction set designed for SIMD machine), AVX machine (machinerunning Advanced Vector Extensions (AVX) instruction set), etc. A SIMDmachine includes only one single PC (program counter). Each instructionstream (i.e., each processor) in SIMD machine is called a lane. Runningof instructions on lanes on a SIMD machine is controlled by apredication mask. The predication mask indicates for each lane whetherthe lane is active for the PC being run or not. When a lane is active,the current PC is run on the lane, otherwise it is not. The predicationmask of a SIMD machine can be updated as the result of other machinesinstructions such as compare, register move, or branch.

SUMMARY

There are provided a system, a method and a computer program product torun SPMD (Single Program Multiple Data) code with diverging control-flowon a SIMD (Single Instruction Multiple Data) machine. The SIMD machineruns an instruction stream which has one thread-PC (Program Counter)over multiple streams of input data. The thread-PC indicates aninstruction memory address which stores an instruction to be fetchednext for the instruction stream. The SIMD machine runs the instructionstream over multiple input data streams (“lanes”). Each lane isassociated with a lane depth counter, a lane-PC to indicate the nextinstruction to be run on the lane, and a lane activation bit to indicatewhether the instruction referred to by the thread-PC is active on thislane or not. The SIMD machine increments lane depth counters of allactive lanes upon the thread-PC reaching a branch operation in theinstruction stream. The SIMD machine updates the lane-PC of each activelane according to targets of the branch operation. The SIMD machineselects one or more lanes, assigns the lane-PC of the selected lane(s)to the thread-PC, and activates only lanes whose lane-PC matches thethread-PC. The SIMD machine decrements the lane depth counters of theselected active lanes and updates the lane-PC of each active lane uponthe instruction stream reaching a particular instruction (e.g., aconvergence instruction). The SIMD machine assigns the lane-PC of a lanewith a largest lane depth counter value to the thread-PC and activatesall lanes whose lane-PCs match the thread-PC. The SIMD machine performsthe running, the incrementing, the assigning, the activating and thedecrementing until the thread-PC reaches an end of the instructionstream and the lane-PC of all lanes match with the thread-PC.

BRIEF DESCRIPTION OF THE DRAWINGS

These and other objects, features and advantages of the presentinvention will become apparent from the following detailed descriptionof illustrative embodiments thereof, which is to be read in connectionwith the accompanying drawings, in which:

FIG. 1A illustrates an example pseudo-code for depicting an examplecontrol-flow divergence in one embodiment;

FIG. 1B illustrates an example control-flow divergence in oneembodiment;

FIGS. 2A-2B illustrate semantics of divergence branch in one embodiment;

FIGS. 3A-3C illustrate semantics of convergence and barrier in oneembodiment;

FIG. 4 illustrates an example splitting of a branch condition in oneembodiment;

FIG. 5 illustrates an example of divergent regions and divergence depthsin one embodiment;

FIG. 6A illustrates example SPMD (Single Program Multiple Data) code inone embodiment; FIG. 6B illustrates example lanes corresponding to theexample SPMD code shown in FIG. 6A in one embodiment;

FIG. 7 illustrates example computing systems that run methods shown inFIG. 8 in one embodiment; and

FIG. 8 illustrates a flowchart that depicts method steps forimplementing control-flow divergence in a SIMD machine in oneembodiment.

DETAILED DESCRIPTION

In one embodiment, a SIMD machine, e.g., SIMD machine 700 shown in FIG.7, optimizes running of SPMD code in the presence of the control-flowdivergence, e.g., by running method steps shown in FIG. 8. The SIMDmachine 700 shown in FIG. 7 includes a plurality of processors, P1, P2,etc. The SIMD machine 700 includes at least two different registers, forexample, 705 and 706, etc. A principle of supporting the SPMD code onthe SIMD machine is to come up with a mechanism to use a singlethread-PC (Program Counter), associated with the SIMD machine, to run aninstruction stream over multiple data streams 105-120 shown in FIG. 1B.A thread-PC indicates an instruction memory address to be run next. Alane is a data stream among a plurality of data streams. A laneactivation bit indicates whether a corresponding lane is active or not.A lane-PC indicates an instruction address to be run on a lane when thelane is activated. A lane depth counter is an integer counter associatedwith each lane. A lane depth counter indicates the number of nestedbranch for each corresponding lane.

In FIG. 1B, a control-flow divergence 125 is defined at a correspondingbranch condition 3 of the SPMD code 100 shown in FIG. 1A. “T” representsthat a branch condition is taken. “F” represents that a branch conditionis not taken. Until the control-flow divergence 125, all the lanes105-120 are active since all the lanes maintain same PCs (an instructionmemory address of the instruction “1” (140)→an instruction memoryaddress of the instruction “2” (145)→an instruction memory address ofthe instruction “3” (150)). From the control-flow divergence 125, SIMDmachine may proceed running the SPMD code over each lane using a singlethread-PC (Program Counter) 105-110, but each lane maintains a differentlane-PC from a point (called diverging path 130) in each lane 105-120.Individual lane-PCs may or may not be the same as the thread-PC. Forexample, a first lane 105 may maintain a lane-PC as the memory addressof the instruction “6” (165) and then the memory address of theinstruction “7” (170). A second lane 110 may maintain a correspondinglane-PC as a memory address of the instruction “4” (155), a memoryaddress of the instruction “5” (160), and a memory address of theinstruction “7” (170). The SIMD machine may run one or more lanes whoselane-PCs are same in parallel in order to maximize the number of activelanes in the SIMD machine.

In one embodiment, one or more compiler of the SIMD machine generatescode during compiling of the SPMD code to be run on the SIMD machine.The generated code includes, but is not limited to: a control-flowstatement (i.e., an instruction code that activates or de-activates oneor more lanes or that instructs the SIMD machine to switch a currentactive lane(s); convergence instruction, diverg_branch instruction,etc.). The advantage of generating and running of this code is that theSIMD machine maximizes the number of active lanes on the SIMD machine.This mechanism, i.e., generating and running of the control-flowstatement, etc., maximizes the performance of the SIMD machine, e.g., byreducing the runtime of the SIMD machine or increasing the throughput ofthe SIMD machine. A value of a lane depth counter stores a depth of a(nested) branch of a corresponding lane which assumes that acorresponding branch condition(s) is taken or not taken.

One of the control-flow statements is convergence that initiates to theSIMD machine that one or more diverging control-flow paths (as theresult of a previous divergent branch) will converge at this point(i.e., at the convergence instruction). With this information, the SIMDmachine starts to run the SPMD code over a different lane which isselected upon the SIMD machine running the convergence instruction. Theselected lane may include a largest depth counter value among all thelanes. The compiler of the SIMD machine inserts one or more convergenceinstructions into SPMD program. By running the convergence instructions,the SIMD machine decides which lane(s) to switch to, in order tominimize running time of the SPMD code. Once the SIMD machine reaches ata convergence instruction in SPMD code the SIMD machine may activate oneor more lanes to run a next instruction in the SPMD code over theactivated lanes.

The SIMD machine includes a register called diverg_depth (also called“lane depth counter register” which is incremented upon the instructionreaches at diverg_branch ddepth vr_target) that helps select one or morelanes upon the SIMD machine reaching the convergence instruction in SPMDcode. The diverg_depth register stores for a corresponding lane a depthof a (nested) branch of the corresponding lane which assumes that acorresponding branch condition(s) is taken or not taken. Upon SIMDmachine processing reaching the convergence instruction, the SIMDmachine switches to the lane(s) with the largest divergence depth (i.e.,a largest diverg_depth counter register value). A diverg_branch ddepthvr_target operation allows a selective increment of diverg_depth whenrunning a branch condition clause based on the value of ddepth: if thevalue of ddepth is a positive value, e.g., one, a diverg_depth counterregister value of a corresponding lane is increased by the positivevalue. If the value of ddepth is zero, the diverg_depth counter registervalue is neither decreased nor increased. In one embodiment, if thevalue of ddepth is a negative value, e.g., −1, a diverg_depth counterregister value of a corresponding lane is decreased by the absolutevalue of that negative value. vr_target is a SIMD machine register. Foran instruction stream i, the SIMD machine branches to an instructionmemory address stored in vr_target.

Another control-flow statement (instruction) is called convergence,which when processed the SIMD machine switches a currently activelane(s), e.g., by activating another lane that minimizes averageinactive lanes during the running of the SIMD machine or by continuouslyactivating the currently active lane(s).

In one embodiment, upon reaching at a convergence instruction, the SIMDmachine selects a lane whose divergence depth (i.e., the differencebetween the lane-PC of an active lane and the instruction memory addressof convergence instruction) is the largest. The SIMD machine activatesthe selected lane and may deactivate other lanes. Another control-flowstatement (instruction) is called barrier which indicates a mandatoryconvergence point for which all lanes join. Barrier may be placed at anentry point of the SPMD code and/or at the end of the SPMD code as shownin FIG. 5. In a further embodiment, the compiler of the SIMD machinegenerates diverg_branch, convergence and barrier instructions. In thisembodiment, there are provided at least three different registers: aregister called diverg_depth, which stores divergence depth for eachlane, a register called lane_pc, which stores a memory address whichstores an instruction to be fetched next when the lane is activated fora corresponding lane, and a register called active_lanes, whichindicates lanes being activated to run the instruction stream.

FIG. 8 illustrates a flowchart that describes method steps to handlecontrol-flow divergence (e.g., control-flow divergence 125 shown in FIG.1—a branch operation) in a SIMD machine in one embodiment. The SIMDmachine initializes values of lane depth counters of all the lanes tozero. The SIMD machine initializes lane-PCs of all the lanes to thethread-PC and activate all lanes. At 800, the SIMD machine runs aninstruction stream which has one thread-PC over multiple streams ofinput data. The thread-PC indicates an instruction memory address whichstores an instruction to be fetched next for the instruction stream. At810, the SIMD machine runs the instruction specified by theThread-PCover all active_lanes.

At 820, the SIMD machine incrementing lane depth counters of allactive_lanes upon the thread-PC reaching a branch operation. At 830, theSIMD machine updates the lane-PC of each active lane according totargets of the branch operation. For example, as shown in FIG. 1A,lane-PCs of first and third lanes take the instruction memory address ofthe instruction “4” (155) upon assuming that the branch operation is nottaken. As shown in FIG. 1A, lane-PCs of second and fourth lanes take theinstruction memory address of the instruction “6” (165) upon assumingthat the branch operation is taken. At 840, the SIMD machine selects alane and assigns the lane-PC of the selected lane to the thread-PC, andactivates only lanes whose lane-PC matches the thread-PC. In oneembodiment, the SIMD machine selects and activates a lane whose lanedepth counter value is the largest. In another embodiment, at 840, theSIMD may randomly select a lane to activate to run the instructionstream over the randomly selected lane. At 850, the SIMD machinedecrements values of corresponding lane depth counters of active_laneswhen the instruction stream reaches a particular instruction, e.g., theconvergence instruction. At 860, the SIMD machine assigns the lane-PC ofthe selected lane with the largest lane depth counter value to be thethread-PC and activates all lanes whose lane-PCs match the thread-PC.

There is provided at least two different convergence instructionplacement algorithms: (1) splitting a branch condition clause into twoor more diverg_branch instructions as shown FIG. 4 which is describedbelow in detail; and (2) a divergence depth error correction mechanismto correct imprecise divergence depth computations as described inpseudo code 230 shown in FIG. 2B which is described in detail below.

FIG. 2A illustrates a flowchart 200 that describes method steps forselecting a lane which becomes an active lane over which the instructionstream is run by the SIMD machine. FIG. 2A corresponds to step 840 inFIG. 8. As shown in pseudo code 210 of FIG. 2A, the SIMD machineinitializes the SIMD machine as follows: (1) the SIMD machine sets allthe values of the diverge_depth counter registers to zero (i.e.,divergence depth is set to zero across all the lanes); (2) lane-PCs ofall lanes are set to the thread-PC; and (3) all lanes to be run over theSPMD code become active to run the SPMD code.

At 235, the SIMD machine runs the diverg_branch ddepth vr_targetinstruction which may be placed in the SPMD code. At 240, a lane-PC ofany active lane is set to a branch target address. At 245, the SIMDmachine evaluates whether a lane depth counter value of each active laneis one. At 250, if the lane depth counter value of the each activeinstruction is one, the SIMD machine increments the lane depth countervalue of the each active lane. At 255 (also shown in pseudo code 220 ofFIG. 2B), if the lane depth counter value of the each active lane is notone, the SIMD machine selects a lane whose value of the lane depthcounter is the largest and activates the selected lane to be run overthe SPMD code. The largest lane depth counter value may indicate thatthe selected lane may include a deepest nested branch.

In a further embodiment, the SIMD machine may run divergence depthcorrection as shown in pseudo code 230 of FIG. 2B. The divergence depthcorrection refers to that after activating the one or more lanes, theSIMD machine assigns a minimum value of lane depth counter values of allactive_lanes to the lane depth counters of all the active_lanes.

FIG. 3A illustrates a flowchart for selecting a lane upon the SIMDmachine reaching at a convergence instruction. At 300, the SIMD machinereaches the convergence instruction. At 305, the SIMD machine incrementsthe lane-PCs of all the active_lanes. At 310, the SIMD machinedecrements values of corresponding lane depth counters of all theactive_lanes. At 315, the SIMD machine selects a lane(s) to activate torun. FIG. 3B illustrates a flowchart for selecting a lane upon the SIMDmachine reaching a barrier which may be an entry point (or an end point)of SPMD code. At 320, a lane reaches at a barrier instruction. At 325,the SIMD machine evaluates whether lane-PCs of all the lanes are set toa same PC (Program Counter). At 330, if the lane-PCs of all the lanesare set to the same PC, the SIMD machine increments the lane-PCs of allthe lanes. If the lane-PCs of all the lanes are not set to the same PC,the SIMD machine selects a lane, e.g., according to the pseudo codeshown in FIG. 3C which is described in detail below.

In a further embodiment, in order to select a lane at 315 and 335 inFIG. 3A, the SIMD machine runs pseudo code illustrated in FIG. 3C.According to the pseudo code shown in FIG. 3C, if all lanes of the SIMDmachine reaches a convergence instruction, at 340-345, the SIMD machineresets lane depth counters of all the lanes to zero. While running thepseudo code 3C, the SIMD machine increments the lane depth countervalues of corresponding lanes whenever the SIMD machine reachesconvergence instruction. At 350, the SIMD machine activates all thelanes. At 355, if lane_pc of lanes do not store a barrier instruction,the SIMD machine selects a lane which includes the largest lane depthcounter register value.

In one embodiment, a region (i.e., a basic code block from a singleentry to a single exit) is called a divergence region in which an entrypoint is a branch condition or an entry point of SPMD program and anexit point is the convergence instruction. For any program point, x, asmallest divergence region is called a proper divergence region of x.

In this embodiment, the compiler of the SIMD machine replaces everyconditional branch with diverg_branch ddepth=0 which resetscorresponding lane depth counter register values of active_lanes thatreach this conditional branch to zero. The compiler of the SIMD machinereplaces every indirect branch with diverg_branch ddepth=0 vr_targ whichresets corresponding lane depth counter register values of active_lanesthat reach this conditional branch to zero and the lane-PCs of theselanes become the values stored in vr_targ register.

In this embodiment, for each divergence region with an entry point x andan exit point y, if x has an incoming edge, i.e., a feedback loop,within the region, the compiler of the SIMD machine may duplicate x intox and x′ so that x is the entry point of the region and has no incomingedge from within the region. This duplication is called node-splittingwhich is described in detail below. At the entry point x, the compilerof the SIMD machine inserts diverg_branch ddepth=1 which increments lanedepth counter values of active_lanes by one. The compiler of the SIMDmachine inserts a convergence instruction right before the exit point y.For each functional call or indirect function call, the compiler of theSIMD machine inserts diverg_branch ddepth=1 at the entry point of acorresponding function and inserts the convergence instruction at theexit point of the corresponding function.

FIG. 4 illustrates an example of node-splitting. The SIMD machine splits430 a branch condition 400 in an example original CFG (Control-FlowGraph) 420 into two or more instructions 440-445, i.e., diverg_branchddepth=1 (440) and diverg_branch ddepth=0 (445). diverg_branch ddepth=1instruction (440) increments a value of a lane depth counter of acorresponding active lane whose corresponding instruction stream hasreached the diverg_branch ddepth=1 instruction (440). diverg_branchddepth=0 instruction (445) obviates incrementing a value of a lane depthcounter of a corresponding active lane whose corresponding instructionstream reaches at diverg_branch ddepth=0 instruction (445). At the endof each iteration of a loop 405, the compiler of the SIMD machine runsthe diverg_branch ddepth=0 instruction (445). In both the original CFG420 and a node-splitting CFG 450, there exists only one incoming edge407. In the node-splitting CFG 450, the compiler of the SIMD machinedirects the incoming edge (“backward branch”) to the diverg_branchddepth=0 instruction (445).

FIG. 5 illustrates example lane depth counter values. “z” (530), “x”(535), “y” (540) and “t” (545) are entry points of SPMD code 500. Inthis SPMD code 500, there are multiple nested loops: a first branchoperation 590 (from an entry point 530 to an exit point 560)—upon anentry of the first branch operation, a lane depth counter value (“dd”)of a corresponding active lane may become one (520), a second branchoperation 575 (from an entry point 535 to an exit point 555)—upon anentry of the second branch 575, the lane depth counter value of thecorresponding active lane may become two (505), a third branch operation580 (from an entry point 540 to an exit point 550)—upon an entry of thethird branch operation 580, the lane depth counter value of thecorresponding lane may become three (515), a fourth branch operation 585(from an entry point 545 to an exit point 570)—upon an entry of thefourth branch 585, a lane depth counter value of another correspondingactive lane may become two (510). Upon all the lanes reaching at abarrier 565, lane depth counter values of all the lanes may become zero(525).

FIG. 6A illustrates example SPMD code 625. FIG. 6B illustratescorresponding example lanes 630, 640, 650 and 660. Upon reaching at afirst branch operation “2: diverg_branch” 600, corresponding lane depthcounter register values increment, for example, lane depth counterregister values of all the lanes become 1. By assuming that the firstbranch operation 600 is taken (“T”), lane-PCs of the second lane 640 andthe fourth lane 660 become an instruction memory address of aninstruction “10: Convergence” (675). By assuming that the first branchoperation 600 is not taken (“F”), lane-PCs of the first lane 630 and thethird lane 650 become an instruction memory address of an instruction“3: a>10” (605).

Upon reaching at a second branch operation “4: diverg_branch” 680, lanedepth counter values of the first and third lanes become two and thelane-PCs of the first and third lanes become each corresponding targetof the second branch operation. By assuming that the second branchoperation 680 is taken, the lane-PC of the first lane 630 becomes aninstruction memory address of the instruction “7: c=1” (615). Byassuming that the second branch operation 680 is not taken, the lane-PCof the third lane 650 becomes an instruction memory address of theinstruction “5: . . . ” (645).

When the SIMD machine runs the instruction “1: b<0” (695), thethread-PC(s) of the instruction stream 625 first takes the lane PCs ofall the lanes 630, 640, 650 and 660. Then, the thread-PC of theinstruction stream 625 takes a value of the lane-PC of the first andthird lanes, i.e., an instruction memory address of the instruction 605,by assuming that the first branch operation 600 is not taken. Then, thethread-PC of the instruction stream 625 takes the lane PC value of thefirst and third lanes, i.e., instruction memory addresses of theinstructions 605 and 680. Thereafter, the thread-PC of the instructionstream 625 takes the lane PC of the first lane 630, i.e., an instructionmemory address of the instruction 615, by assuming that the secondbranch operation 680 is taken. Then, the thread-PC of the instruction625 takes the lane-PC of the first lane 630, i.e., an instruction memoryaddress of the instruction 635 which is a convergence instruction whichcan initiate the SIMD machine to switch a currently active lane (i.e.,the first lane 630). Then by activating the third lane 650 anddeactivating the first lane 630, the first thread-PC of the instructionstream 625 takes the lane-PC of the third lane 650, i.e., instructionmemory addresses of the instructions “5: . . . ” (645), followed by “6:goto 8” (655), and followed by “8: convergence” (635).) The instruction635 is a convergence instruction at which the SIMD machine can activateanother lane, e.g., the first lane 630, as well as the third lane 650 inorder to run instructions 635, 665 and 675 over the first lane 630 andthe third lane 650. Upon reaching the convergence instruction 635, lanedepth counter values of all the active lanes decrement by one. At 620,the lane depth counter values of all the lanes become one. Since at 620the largest lane depth counter value is one and all the lane depthcounters' values are one, the SIMD machine activates all the lanes,i.e., lanes 630, 640, 650 and 660. Upon running the instruction “10:convergence” (675), the lane depth counter values of the all the lanesbecome zero. By running the instruction “10: convergence” (675), theSIMD machine activates all the lanes whose lane-PCs match with thethread-PCs which store an instruction memory address of the instruction685.

Lane depth counter register values are computed at runtime andmanipulated by both convergence and diverg_branch instructions. Byrunning the convergence or diverg_branch instruction, the SIMD machinecomputes the lane depth counter register values of corresponding lanes,e.g., by incrementing whenever the instruction stream reaches atdiverg_branch ddepth=1 instruction and decrementing whenever theinstruction stream reaches at convergence instruction.

In one embodiment, the compiler of the SIMD machine places theconvergence and diverg_branch instructions in SPMD code. The compiler ofthe SIMD machine replaces branch operations with diverg_branchinstructions. By replacing each branch operation with a diverg_branchinstruction, the compiler of the SIMD machine constructs CFG, e.g., SPMDcode 625 shown in FIG. 6A. In the constructed CFG, the compiler of theSIMD machine inserts a convergence instruction at the end of each block(i.e., from an entry point indicated by diverg_branch instruction to anexit point indicated by convergence instruction) which includes morethan one incoming edges where none are backward edges, e.g., a backwardedge 407 shown in FIG. 4. In the constructed CFG, the compiler of theSIMD machine inserts the convergence instruction at the exit point ofeach function call. In a case of the lane depth counter overflow, theSIMD machine can run corresponding SPMD code correctly as the lane depthcounter value is not a requirement for a correct computation of the SPMDcode. The diverg_branch and convergence instructions are instructionsfor maximizing parallelism in the SIMD machine and do not impactcomputation correctness.

In one embodiment, upon reaching a diverg_branch instruction, the SIMDmachine does not activate another lane, and the thread-PC of acorresponding instruction stream becomes a branch target stored invr_target register. In this embodiment, upon meeting a convergenceinstruction, the thread-PC may become an instruction memory addressstored in lane_pc register of a deactivated lane. The SIMD machineswitches lanes depending on values in lane_pc and diverg_depthregisters. In this embodiment, one or more operations in the SPMD codemay overwrite register values of one or more lanes. Running of aninstruction stream over one or more lanes may overwrite register valuesof other lanes.

FIG. 7 illustrates an example SIMD machine 700. The example SIMD machinemay include, but are not limited to: a plurality of processors (P1, P2,. . . , Pn, . . . ) which are connected to each other. The SIMD machinemay also include one or more shared memory devices (not shown). Eachprocessor in the SIMD machine may include one or more processing cores(not shown) and one or more local memory devices (not shown).

In one embodiment, the methods shown in FIG. 10 may be implemented ashardware on a reconfigurable hardware, e.g., FPGA (Field ProgrammableGate Array) or CPLD (Complex Programmable Logic Device), by using ahardware description language (Verilog, VHDL, Handel-C, or System C). Inanother embodiment, the method shown in FIG. 10 may be implemented on asemiconductor chip, e.g., ASIC (Application-Specific IntegratedCircuit), by using a semi-custom design methodology, i.e., designing asemiconductor chip using standard cells and a hardware descriptionlanguage.

The present invention may be a system, a method, and/or a computerprogram product. The computer program product may include a computerreadable storage medium (or media) having computer readable programinstructions thereon for causing a processor to carry out aspects of thepresent invention.

The computer readable storage medium can be a tangible device that canretain and store instructions for use by a device that runs aninstruction. The computer readable storage medium may be, for example,but is not limited to, an electronic storage device, a magnetic storagedevice, an optical storage device, an electromagnetic storage device, asemiconductor storage device, or any suitable combination of theforegoing. A non-exhaustive list of more specific examples of thecomputer readable storage medium includes the following: a portablecomputer diskette, a hard disk, a random access memory (RAM), aread-only memory (ROM), an erasable programmable read-only memory (EPROMor Flash memory), a static random access memory (SRAM), a portablecompact disc read-only memory (CD-ROM), a digital versatile disk (DVD),a memory stick, a floppy disk, a mechanically encoded device such aspunch-cards or raised structures in a groove having instructionsrecorded thereon, and any suitable combination of the foregoing. Acomputer readable storage medium, as used herein, is not to be construedas being transitory signals per se, such as radio waves or other freelypropagating electromagnetic waves, electromagnetic waves propagatingthrough a waveguide or other transmission media (e.g., light pulsespassing through a fiber-optic cable), or electrical signals transmittedthrough a wire.

Computer readable program instructions described herein can bedownloaded to respective computing/processing devices from a computerreadable storage medium or to an external computer or external storagedevice via a network, for example, the Internet, a local area network, awide area network and/or a wireless network. The network may comprisecopper transmission cables, optical transmission fibers, wirelesstransmission, routers, firewalls, switches, gateway computers and/oredge servers. A network adapter card or network interface in eachcomputing/processing device receives computer readable programinstructions from the network and forwards the computer readable programinstructions for storage in a computer readable storage medium withinthe respective computing/processing device.

Computer readable program instructions for carrying out operations ofthe present invention may be assembler instructions,instruction-set-architecture (ISA) instructions, machine instructions,machine dependent instructions, microcode, firmware instructions,state-setting data, or either source code or object code written in anycombination of one or more programming languages, including an objectoriented programming language such as Java, Smalltalk, C++ or the like,and conventional procedural programming languages, such as the “C”programming language or similar programming languages. The computerreadable program instructions may run entirely on the user's computer,partly on the user's computer, as a stand-alone software package, partlyon the user's computer and partly on a remote computer or entirely onthe remote computer or server. In the latter scenario, the remotecomputer may be connected to the user's computer through any type ofnetwork, including a local area network (LAN) or a wide area network(WAN), or the connection may be made to an external computer (forexample, through the Internet using an Internet Service Provider). Insome embodiments, electronic circuitry including, for example,programmable logic circuitry, field-programmable gate arrays (FPGA), orprogrammable logic arrays (PLA) may run the computer readable programinstructions by utilizing state information of the computer readableprogram instructions to personalize the electronic circuitry, in orderto perform aspects of the present invention.

Aspects of the present invention are described herein with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems), and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer readable program instructions.

These computer readable program instructions may be provided to aprocessor of a general purpose computer, special purpose computer, orother programmable data processing apparatus to produce a machine, suchthat the instructions, which run via the processor of the computer orother programmable data processing apparatus, create means forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks. These computer readable program instructionsmay also be stored in a computer readable storage medium that can directa computer, a programmable data processing apparatus, and/or otherdevices to function in a particular manner, such that the computerreadable storage medium having instructions stored therein comprises anarticle of manufacture including instructions which implement aspects ofthe function/act specified in the flowchart and/or block diagram blockor blocks.

The computer readable program instructions may also be loaded onto acomputer, other programmable data processing apparatus, or other deviceto cause a series of operational steps to be performed on the computer,other programmable apparatus or other device to produce a computerimplemented process, such that the instructions which run on thecomputer, other programmable apparatus, or other device implement thefunctions/acts specified in the flowchart and/or block diagram block orblocks.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof instructions, which comprises one or more executable instructions forimplementing the specified logical function(s). In some alternativeimplementations, the functions noted in the block may occur out of theorder noted in the figures. For example, two blocks shown in successionmay, in fact, be run substantially concurrently, or the blocks maysometimes be run in the reverse order, depending upon the functionalityinvolved. It will also be noted that each block of the block diagramsand/or flowchart illustration, and combinations of blocks in the blockdiagrams and/or flowchart illustration, can be implemented by specialpurpose hardware-based systems that perform the specified functions oracts or carry out combinations of special purpose hardware and computerinstructions.

What is claimed is:
 1. A method for selecting an active data streamwhile running a SPMD (Single Program Multiple Data) program ofinstructions on a SIMD (Single Instruction Multiple Data) machine, aninstruction stream having one thread-PC (Program Counter), a value ofthe thread-PC indicating an instruction memory address which stores aninstruction to be fetched next for the instruction stream, comprising;running the instruction stream over a plurality of input data streamseach of which corresponds to each of a plurality of lanes, each of theplurality of lanes being associated with a corresponding lane depthcounter indicating a number of nested branches for each correspondinglane, a corresponding lane-PC of a lane of the plurality of lanesindicating a memory address which stores the instruction to be fetchednext for the lane when the lane is activated, and a lane activation bitindicating whether the lane is active or not; incrementing values of thelane depth counters of all active_lanes of the plurality of lanes uponthe thread-PC value reaching a branch operation in the instructionstream; updating the lane-PC value of each of the active_lanes accordingto targets of the branch operation; and selecting at least one activelane from the plurality of lanes and assigning a corresponding lane-PCvalue of the selected at least one active lane to the thread-PC, andactivating only lanes of the plurality of lanes whose lane-PC values areequal to the thread-PC value.
 2. The method according to claim 1,further comprising: decrementing the lane depth counter value of theselected at least one active lane and updating the lane-PC value of eachof the plurality of active_lanes upon the instruction stream reaching afirst instruction; and assigning the lane-PC value of a lane of theplurality of lanes with a largest lane depth counter value to thethread-PC and activating all lanes of the plurality of lanes whoselane-PC values are equal to the thread-PC value.
 3. The method accordingto claim 2, wherein a plurality of processors coupled to one or morememory devices perform the running, the incrementing, the assigning, theactivating and the decrementing until the thread-PC reaches an end ofthe instruction stream and the lane-PC values of all of the plurality oflanes are equal to with the thread-PC value.
 4. The method according toclaim 1, further comprising: incrementing the values of the lane depthcounters of all the active_lanes of the plurality of lanes when theinstruction stream reaches a second instruction.
 5. The method accordingto claim 1, further comprising: initializing the values of the lanedepth counters of all of the plurality of lanes to zero; initializingthe values of the lane-PCs of all of the plurality of lanes to aninstruction memory address; and activating one or more lanes of theplurality of lanes whose lane-PC values are set to the instructionmemory address.
 6. The method according to claim 1, further comprising:after activating one or more lanes of the plurality of lanes, assigninga minimum value of values of lane depth counters of all anotheractive_lanes of the plurality of lanes to the values of the lane depthcounters of all the another active_lanes.
 7. The method according toclaim 1, wherein the incrementing comprises: splitting the branchoperation into two second instructions and directing a backward branchto one of the two second instructions.
 8. The method according to claim7, wherein another of the two second instructions specifies a positiveincrement value.
 9. The method according to claim 7, wherein the one ofthe two second instructions specifies a zero increment value.
 10. Asystem for selecting an active data stream while running a SPMD (SingleProgram Multiple Data) program of instructions on a SIMD (SingleInstruction Multiple Data) machine, an instruction stream having onethread-PC (Program Counter), a value of the thread-PC indicating aninstruction memory address which stores an instruction to be fetchednext for the instruction stream, the system comprising: a plurality ofprocessors; a memory device coupled to the plurality of processors,wherein the plurality of processors are configured to perform: runningthe instruction stream over a plurality of input data streams each ofwhich corresponds to each of a plurality of lanes, each of the pluralityof lanes being associated with a corresponding lane depth counterindicating a number of nested branches for each corresponding lane, acorresponding lane-PC of a lane of the plurality of lanes indicating amemory address which stores the instruction to be fetched next for thelane when the lane is activated, and a lane activation bit indicatingwhether the lane is active or not; incrementing values of the lane depthcounters of all active_lanes of the plurality of lanes upon thethread-PC value reaching a branch operation in the instruction stream;updating the lane-PC value of each of the active_lanes according totargets of the branch operation; and selecting at least one active lanefrom of the plurality of lanes and assigning a corresponding lane-PCvalue of the selected at least one active lane to the thread-PC, andactivating only lanes of the plurality of lanes whose lane-PC values areequal toes the thread-PC value.
 11. The system according to claim 10,wherein the plurality of processors are further configured to perform:decrementing the lane depth counter values of the selected at least oneactive lane and updating the lane-PC value of each of the plurality ofactive_lanes upon the instruction stream reaching a first instruction;and assigning the lane-PC value of a lane of the plurality of lanes witha largest lane depth counter value to the thread-PC and activating alllanes of the plurality of lanes whose lane-PC values are equal to thethread-PC value.
 12. The system according to claim 10, wherein theplurality of processors are coupled to one or more memory devices andare configured to perform the running, the incrementing, the assigning,the activating and the decrementing until the thread-PC reaches an endof the instruction stream and the lane-PC values of all of the pluralityof lanes are equal to with the thread-PC value.
 13. The system accordingto claim 10, wherein the plurality of processors are further configuredto perform: incrementing the values of the lane depth counters of all ofthe active_lanes of the plurality of lanes when the instruction streamreaches a second instruction.
 14. The system according to claim 10,wherein in order to perform the running, the plurality of processors arefurther configured to perform: initializing the values of the lane depthcounters of all of the plurality of lanes to zero; initializing thevalues of the lane-PCs of all of the plurality of lanes to aninstruction memory address; and activating one or more lanes of theplurality of lanes whose lane-PC values are set to the instructionmemory address.
 15. The system according to claim 10, wherein theplurality of processors are further configured to perform: afteractivating one or more lanes of the plurality of lanes, assigning aminimum value of values of lane depth counters of all anotheractive_lanes of the plurality of lanes to the value of the lane depthcounters of all the another active_lanes.
 16. A computer program productfor selecting an active data stream while running a SPMD (Single ProgramMultiple Data) program of instructions on a SIMD (Single InstructionMultiple Data) machine, an instruction stream having one thread-PC(Program Counter), a value of the thread-PC indicating an instructionmemory address which stores an instruction to be fetched next for theinstruction stream, the computer program product comprising a computerreadable storage medium readable by a machine and storing instructionsrun by the machine to perform a method, said method steps comprising:running the instruction stream over a plurality of input data streamseach of which corresponds to each of a plurality of lanes, each of theplurality of lanes being associated with a corresponding lane depthcounter indicating a number of nested branches for each correspondinglane, a corresponding lane-PC of a lane of the plurality of lanesindicating a memory address which stores the instruction to be fetchednext for the lane when the lane is activated, and a lane activation bitindicating whether the lane is active or not; incrementing values of thelane depth counters of all active_lanes of the plurality of lanes uponthe thread-PC value reaching a branch operation in the instructionstream; updating the lane-PC value of each of the active_lanes accordingto targets of the branch operation; and selecting at least one activelane from the plurality of lanes and assigning a corresponding lane-PCvalue of the selected at least one active lane to the thread-PC, andactivating only lanes of the plurality of lanes whose lane-PC values areequal to the thread-PC value.
 17. The computer program product accordingto claim 16, wherein the method steps further comprise: decrementing thelane depth counter value of the selected at least one active lane andupdating the lane-PC value of each of the plurality of active_lanes uponthe instruction stream reaching a first instruction; and assigning thelane-PC value of a lane of the plurality of lanes with a largest lanedepth counter value to the thread-PC and activating all lanes of theplurality of lanes whose lane-PC values are equal to the thread-PCvalue.
 18. The computer program product according to claim 16, whereinthe method steps further comprise: incrementing the values of the lanedepth counters of all the active_lanes of the plurality of lanes whenthe instruction stream reaches a second instruction.
 19. The computerprogram product according to claim 16, wherein the running comprises:initializing the values of the lane depth counters of all of theplurality of lanes to zero; initializing the values of the lane-PCs ofall of the plurality of lanes to an instruction memory address; andactivating one or more lanes of the plurality of lanes whose lane-PCvalues are set to the instruction memory address.
 20. The computerprogram product according to claim 16, wherein the method steps furthercomprise: after activating one or more lanes of the plurality of lanes,assigning a minimum value of values of lane depth counters of allanother active_lanes of the plurality of lanes to the values of the lanedepth counters of all the another active_lanes.